﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Luna小店.UC.项目成果管理.在制品管理.service;
using DevExpress.XtraGrid.Demos.util;
using Luna小店.UC.项目成果管理.service;
using Luna小店.UC.项目成果管理.在制品管理.model;

namespace Luna小店.UC.项目成果管理.在制品管理
{
    public partial class FormVI质检 : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        private String code;
        private String styleId;
        private List<DTO半成品量尺> list半成品量尺 = new List<DTO半成品量尺>();
        private List<DTO半成品量尺呈现> list半成品量尺呈现 = new List<DTO半成品量尺呈现>();
        private DTO项目成果提交 DTO项目成果提交 = new DTO项目成果提交();
        public FormVI质检(String code)
        {
            InitializeComponent();
            this.code = code;
        }

        private void textBox扫码_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                this.styleId = this.textBox扫码.Text.Trim();
                this.刷新显示半成品量尺();
            }
        }

        private void repositoryItemCheckEdit1_Click(object sender, EventArgs e)
        {
            try
            {
                在制品管理Service.post半成品量尺检查(this.styleId, this.treeList半成品量尺.FocusedNode["id"].ToString());
                this.刷新显示半成品量尺();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void 刷新显示半成品量尺()
        {
            try
            {
                this.list半成品量尺 = 在制品管理Service.get半成品量尺(this.styleId);
                //转换显示
                this.list半成品量尺呈现 = new 在制品管理Model().build半成品量尺显示(this.list半成品量尺);
                this.treeList半成品量尺.DataSource = this.list半成品量尺呈现;
                this.treeList半成品量尺.ExpandAll();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void barButtonItem提交_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (string.IsNullOrEmpty(this.styleId) 
                    || string.IsNullOrEmpty(this.code) 
                        || this.list半成品量尺.Count == 0
                        )
            {
                MessageBox.Show("无扫描内容");
                return;
            }
            this.DTO项目成果提交.styleId = this.styleId;
            this.DTO项目成果提交.code = this.code;
            this.DTO项目成果提交.content = FunctionHelper.JsonSerialization(this.list半成品量尺);
            new Form项目成果提交(this.DTO项目成果提交).ShowDialog();
        }
        
        private void treeList半成品量尺_CustomDrawNodeCell(object sender, DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs e)
        {
            if (e.Column.Name == "treeListColumnIfPass")
            {
                DTO半成品量尺呈现 row = treeList半成品量尺.GetDataRecordByNode(e.Node) as DTO半成品量尺呈现;
                if (row.ifPass.Equals("未通过"))
                {
                    e.Appearance.BackColor = Color.Red;
                    e.Appearance.ForeColor = Color.White;
                }
                else if (row.ifPass.Equals("通过"))
                {
                    e.Appearance.BackColor = Color.Green;
                    e.Appearance.ForeColor = Color.White;
                }
            }
        }
    }
}